package com.example.handler;

import com.lly835.bestpay.model.PayResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SysPayCallBackHandler {

    @Resource
    private List<SysPayHandler> sysPayHandlers = new ArrayList<SysPayHandler>();

    /****
     * 获取准确的回调处理器
     * @param response
     * @return
     */
    public SysPayHandler getHandler(PayResponse response) {
        for (SysPayHandler sysPayHandler : sysPayHandlers) {
            if (sysPayHandler.match(response)) {
                return sysPayHandler;
            }
        }
        return null;
    }

    /***
     * 回调
     * @return
     */
    public String callBack(PayResponse response) {
        return getHandler(response).response(response);
    }
}
